package com.bole.controller;

import com.bole.data.Result;
import com.bole.data.ResultEnum;
import com.bole.dto.content.DicContentTypeDto;
import com.bole.feign.ContentTypeFeign;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;


@Controller
@RequestMapping("contenttype")
@Api(value = "广告分类管理接口")
public class ContentTypeController {

    @Autowired
    private ContentTypeFeign contentTypeFeign;

    @RequestMapping("toList")
    public String toList(){
        return "/content/content-type-list";
    }



    @GetMapping("getContentTypeInfo")
    @ApiOperation(value = "查询广告分类信息",notes = "查询广告分类信息")
    @ResponseBody
    public Result getContentCateInfo(){
        List<DicContentTypeDto> list =  contentTypeFeign.getContentInfo();
        return Result.response(ResultEnum.OK).setData(list);
    }


    @PostMapping("saveContentTypeInfo")
    @ApiOperation(value = "增加广告分类信息",notes = "增加广告分类信息")
    @ApiImplicitParam(name = "dicContentTypeDto",value = "广告分类对象",required = true,dataTypeClass = DicContentTypeDto.class)
    @ResponseBody
    public Result saveContentCateInfo(@RequestBody DicContentTypeDto dicContentTypeDto){
        contentTypeFeign.saveContentCateInfo(dicContentTypeDto);
        return Result.response(ResultEnum.OK);
    }


    @PostMapping("toUpdate/{id}")
    @ApiOperation(value = "广告信息回显",notes = "没啥好注释的")
    @ApiImplicitParam(name = "id",value = "广告id",required = true,dataTypeClass = Long.class)
    @ResponseBody
    public Result toUpdate(@PathVariable("id")Long id){
        DicContentTypeDto contentTypeDto = contentTypeFeign.toUpdate(id);
        return Result.response(ResultEnum.OK).setData(contentTypeDto);
    }


    @PostMapping("updateContentCateInfo")
    @ApiOperation(value = "修改广告分类信息",notes = "广告分类信息")
    @ApiImplicitParam(name = "dicContentTypeDto",value = "广告分类对象",required = true,dataTypeClass = DicContentTypeDto.class)
    @ResponseBody
    public Result updateContentCateInfo(@RequestBody DicContentTypeDto dicContentTypeDto){
        contentTypeFeign.updateContentCateInfo(dicContentTypeDto);
        return Result.response(ResultEnum.OK);
    }


    @PostMapping("deleteBatch/{ids}")
    @ApiOperation(value = "批量删除信息",notes = "批量删除信息")
    @ApiImplicitParam(name = "ids",value = "广告id集",required = true,paramType = "path",dataTypeClass = Long.class)
    @ResponseBody
    public Result deleteBatch(@PathVariable("ids")Long[] ids){
        List<Long> idss = new ArrayList<>();
        for (Long id : ids) {
            idss.add(id);
        }
        contentTypeFeign.deleteBatch(idss);
        return Result.response(ResultEnum.OK);
    }

}
